package org.loofer.ext.component.drawable;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class SpecifiedDrawable extends DrawableDecorator {
    private SpecificState mState;

    static class SpecificState extends DrawableDecoratorState {
        int mHeight;
        int mWidth;

        SpecificState(SpecificState orig, DrawableDecorator owner, Resources res) {
            super(orig, owner, res);
            if (orig != null) {
                this.mWidth = orig.mWidth;
                this.mHeight = orig.mHeight;
            }
        }

        public Drawable newDrawable() {
            return new SpecifiedDrawable(this, null);
        }
    }

    public SpecifiedDrawable(Drawable drawable) {
        this(drawable, -1, -1);
    }

    public SpecifiedDrawable(Drawable drawable, int width, int height) {
        this.mState = new SpecificState(null, this, null);
        this.mState.setDrawable(drawable);
        this.mState.mWidth = width;
        this.mState.mHeight = height;
        setConstantState(this.mState);
    }

    public void resize(int width, int height) {
        if (this.mState.mWidth != width || this.mState.mHeight != height) {
            this.mState.mWidth = width;
            this.mState.mHeight = height;
            invalidateSelf();
        }
    }

    public int getIntrinsicWidth() {
        int width = this.mState.mWidth;
        return width > 0 ? width : super.getIntrinsicWidth();
    }

    public int getIntrinsicHeight() {
        int height = this.mState.mHeight;
        return height > 0 ? height : super.getIntrinsicHeight();
    }

    public int getOrginalWidth() {
        return super.getIntrinsicWidth();
    }

    public int getOriginalHeight() {
        return super.getIntrinsicHeight();
    }

    private SpecifiedDrawable(SpecificState state, Resources res) {
        this.mState = new SpecificState(state, this, res);
        setConstantState(this.mState);
    }
}
